(function(){
	
	function PicutreUpload() {
		this.API = {
			brand_photographers: null
		};
	};
	
	// attach all js events which will be used in image upload page.
	PicutreUpload.prototype.bindEvents = function() {
		
		var self = this;
		
		// event for brand switch
		$("#brandSel").bind("change", function(event) {
			self.changeBrand(this, event);
		});
		
	};
	
	PicutreUpload.prototype.changeBrand = function(element, event) {
		
		element = $(element);
		
		var brandId = element.val();
		
		if (brandId == "") {
			$("#photographerSel").html('<option value="">请选择摄影师</option>');
		}
		else {
			
			// query photographer in this brand
			$.ajax({
				url:this.API.brand_photographers,
				type:"post",
				data:{
					brandId:brandId
				}
			}).done(function(data){
				
				$("#photographerSel").html(data);
				
			}).fail(function(jqXHR, textStatus){
				alert("error query for photographer.");
			});
			
		}
	};
	
	window.PictureEdit = new PicutreUpload();
	
	$(function(){
		PictureEdit.bindEvents();
	});
	
})();